import java.util.Locale;

/**
 * @BelongsProject : LeetCode
 * @Author : WXY
 * @CreateTime : 2022-12-04  22:22
 * @Description : 剑指 Offer 05. 替换空格
 * @Version : 1.0
 */

public class Num05_replaceSpace {
    public static String replaceSpace(String s) {
        StringBuilder sb = new StringBuilder();
        char[] str = s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            if (str[i] == ' ') {
                sb.append("%20");
            } else {
                sb.append(str[i]);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = "sfd sadf safsjaf ";
        String s1 = replaceSpace(s);
        System.out.println(s1);

    }
}
